<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', function() {
	$var = 'Login please';
	if (Auth::check()) {
		$var = 'Welcome ' . Auth::user()->name;
	}

	if (Auth::viaRemember()) {
	    $var .= ' [remember]';
	}

    return $var;
});

// session
Route::post('session', 'AuthController@doLogin');	
Route::get('session', 'AuthController@doLogout');

// users
Route::group(array('prefix' => 'users'), function() {
	Route::resource('/', 'UserController');

	// se definen las validaciones para los usuarios
    Route::group(array('prefix' => 'validations'), function() {
    	Route::get('checkUsernameExists', 'UserController@checkUsernameExists');
    });
});


// rutas que sólo se pueden acceder si se esta autenticado
Route::group(array(/*'prefix' => 'api/v1',*/ 'before' => 'auth.basic'), function() {
    Route::resource('messages', 'MessagesController');
});


